(* Content-type: application/mathematica *)

(*** Wolfram Notebook File ***)
(* http://www.wolfram.com/nb *)

(* CreatedBy='Mathematica 7.0' *)

(*CacheID: 234*)
(* Internal cache information:
NotebookFileLineBreakTest
NotebookFileLineBreakTest
NotebookDataPosition[       145,          7]
NotebookDataLength[      7802,        232]
NotebookOptionsPosition[      7482,        217]
NotebookOutlinePosition[      7863,        233]
CellTagsIndexPosition[      7820,        230]
WindowFrame->Normal*)

(* Beginning of Notebook Content *)
Notebook[{
Cell[BoxData[{
 RowBox[{"Needs", "[", "\"\<MathOO`\>\"", "]"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"NewClass", "[", "dict", "]"}], ";"}], "\n", 
 RowBox[{
  RowBox[{
   RowBox[{"dict", ".", 
    RowBox[{"$init$", "[", 
     RowBox[{"self_", ",", "items___"}], "]"}]}], ":=", 
   RowBox[{"Module", "[", 
    RowBox[{
     RowBox[{"{", "$attr$", "}"}], ",", "\[IndentingNewLine]", 
     RowBox[{
      RowBox[{
       RowBox[{"self", "[", "\"\<$dict\>\"", "]"}], "=", "$attr$"}], ";", 
      "\[IndentingNewLine]", 
      RowBox[{"If", "[", 
       RowBox[{
        RowBox[{"items", "=!=", "Null"}], ",", 
        RowBox[{"Scan", "[", 
         RowBox[{
          RowBox[{
           RowBox[{"(", 
            RowBox[{
             RowBox[{"$attr$", "[", 
              RowBox[{
              "#", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}], 
              "]"}], "=", 
             RowBox[{
             "#", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}]}], 
            ")"}], "&"}], ",", 
          RowBox[{"{", "items", "}"}]}], "]"}]}], "]"}], ";"}]}], 
    "\[IndentingNewLine]", "]"}]}], ";"}], "\n", 
 RowBox[{
  RowBox[{"dict", ".", 
   RowBox[{"put", "[", 
    RowBox[{"self_", ",", "key_", ",", "value_"}], "]"}]}], ":=", 
  RowBox[{"(", 
   RowBox[{
    RowBox[{
     RowBox[{
      RowBox[{"self", "[", "\"\<$dict\>\"", "]"}], "[", "key", "]"}], "=", 
     "value"}], ";", "self"}], ")"}]}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{
   RowBox[{"dict", ".", 
    RowBox[{"get", "[", 
     RowBox[{"self_", ",", "key_", ",", 
      RowBox[{"default_:", "Null"}]}], "]"}]}], ":=", 
   RowBox[{"If", "[", 
    RowBox[{
     RowBox[{"hasAttr", "[", 
      RowBox[{
       RowBox[{"self", "[", "\"\<$dict\>\"", "]"}], ",", "key"}], "]"}], ",", 
     RowBox[{
      RowBox[{"self", "[", "\"\<$dict\>\"", "]"}], "[", "key", "]"}], ",", 
     "default"}], "]"}]}], ";"}], "\n", 
 RowBox[{
  RowBox[{"dict", ".", 
   RowBox[{"values", "[", "self_", "]"}]}], ":=", 
  RowBox[{
   RowBox[{"DownValues", "[", 
    RowBox[{
     RowBox[{"Evaluate", "[", 
      RowBox[{"self", "[", "\"\<$dict\>\"", "]"}], "]"}], ",", 
     RowBox[{"Sort", "\[Rule]", "False"}]}], "]"}], "\[LeftDoubleBracket]", 
   RowBox[{"All", ",", "2"}], "\[RightDoubleBracket]"}]}], "\n", 
 RowBox[{
  RowBox[{"dict", ".", 
   RowBox[{"keys", "[", "self_", "]"}]}], ":=", 
  RowBox[{
   RowBox[{"DownValues", "[", 
    RowBox[{
     RowBox[{"Evaluate", "[", 
      RowBox[{"self", "[", "\"\<$dict\>\"", "]"}], "]"}], ",", 
     RowBox[{"Sort", "\[Rule]", "False"}]}], "]"}], "\[LeftDoubleBracket]", 
   RowBox[{"All", ",", "1", ",", "1", ",", "1"}], 
   "\[RightDoubleBracket]"}]}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"dict", ".", 
   RowBox[{"items", "[", "self_", "]"}]}], ":=", 
  RowBox[{
   RowBox[{
    RowBox[{"{", 
     RowBox[{
      RowBox[{"#", "\[LeftDoubleBracket]", 
       RowBox[{"1", ",", "1", ",", "1"}], "\[RightDoubleBracket]"}], ",", 
      RowBox[{"#", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}]}], 
     "}"}], "&"}], "/@", 
   RowBox[{"DownValues", "[", 
    RowBox[{
     RowBox[{"Evaluate", "[", 
      RowBox[{"self", "[", "\"\<$dict\>\"", "]"}], "]"}], ",", " ", 
     RowBox[{"Sort", "\[Rule]", "False"}]}], "]"}]}]}], "\n", 
 RowBox[{
  RowBox[{"dict", ".", 
   RowBox[{"addList", "[", 
    RowBox[{"self_", ",", "x__"}], "]"}]}], ":=", 
  RowBox[{"Block", "[", 
   RowBox[{
    RowBox[{"{", 
     RowBox[{"$d", "=", 
      RowBox[{"self", "[", "\"\<$dict\>\"", "]"}]}], "}"}], ",", 
    RowBox[{
     RowBox[{"Scan", "[", 
      RowBox[{
       RowBox[{
        RowBox[{"(", 
         RowBox[{
          RowBox[{"$d", "[", 
           RowBox[{
           "#", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}], "]"}],
           "=", 
          RowBox[{
          "#", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}]}], 
         ")"}], "&"}], ",", 
       RowBox[{"{", "x", "}"}]}], "]"}], ";", "self"}]}], 
   "]"}]}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"dict", ".", 
   RowBox[{"update", "[", 
    RowBox[{"self_", ",", "dict_"}], "]"}]}], ":=", 
  RowBox[{"Block", "[", 
   RowBox[{
    RowBox[{"{", 
     RowBox[{
      RowBox[{"$d", "=", 
       RowBox[{"self", "[", "\"\<$dict\>\"", "]"}]}], ",", 
      "\[IndentingNewLine]", 
      RowBox[{"items", "=", 
       RowBox[{
        RowBox[{
         RowBox[{"{", 
          RowBox[{
           RowBox[{"#", "\[LeftDoubleBracket]", 
            RowBox[{"1", ",", "1", ",", "1"}], "\[RightDoubleBracket]"}], ",", 
           RowBox[{
           "#", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}]}], 
          "}"}], "&"}], "/@", 
        RowBox[{"DownValues", "[", 
         RowBox[{
          RowBox[{"Evaluate", "[", 
           RowBox[{"dict", "[", "\"\<$dict\>\"", "]"}], "]"}], ",", " ", 
          RowBox[{"Sort", "\[Rule]", "False"}]}], "]"}]}]}]}], "}"}], ",", 
    "\[IndentingNewLine]", 
    RowBox[{
     RowBox[{"Scan", "[", 
      RowBox[{
       RowBox[{
        RowBox[{"(", 
         RowBox[{
          RowBox[{"$d", "[", 
           RowBox[{
           "#", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}], "]"}],
           "=", 
          RowBox[{
          "#", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}]}], 
         ")"}], "&"}], ",", "items"}], "]"}], ";", "\[IndentingNewLine]", 
     "self"}]}], "]"}]}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"dict", ".", 
   RowBox[{"clear", "[", "self_", "]"}]}], ":=", 
  RowBox[{"(", 
   RowBox[{
    RowBox[{"Clear", "[", 
     RowBox[{"Evaluate", "[", 
      RowBox[{"self", "[", "\"\<$dict\>\"", "]"}], "]"}], "]"}], ";", 
    "self"}], ")"}]}], "\n", 
 RowBox[{
  RowBox[{
   RowBox[{"dict", ".", 
    RowBox[{"hasKey", "[", 
     RowBox[{"self_", ",", "key_"}], "]"}]}], ":=", 
   RowBox[{"hasAttr", "[", 
    RowBox[{
     RowBox[{"self", "[", "\"\<$dict\>\"", "]"}], ",", "key"}], "]"}]}], 
  ";"}], "\n", 
 RowBox[{
  RowBox[{"dict", ".", 
   RowBox[{"length", "[", "self_", "]"}]}], ":=", 
  RowBox[{"Length", "[", 
   RowBox[{"DownValues", "[", 
    RowBox[{"Evaluate", "[", 
     RowBox[{"self", "[", "\"\<$dict\>\"", "]"}], "]"}], "]"}], 
   "]"}]}]}], "Input",
 InitializationCell->True,
 CellChangeTimes->{{3.4973634595*^9, 3.497363460265625*^9}, {3.497394588*^9, 
  3.49739459978125*^9}, {3.4973948134375*^9, 3.4973948415*^9}, {
  3.49740160203125*^9, 3.4974016658125*^9}, {3.497434997671875*^9, 
  3.497435023421875*^9}, {3.49768394571875*^9, 3.497683950546875*^9}, {
  3.497938202453125*^9, 3.497938202875*^9}, {3.498171976328125*^9, 
  3.498172149859375*^9}, {3.49817239328125*^9, 3.49817240153125*^9}, {
  3.498172574859375*^9, 3.498172765046875*^9}, {3.498173278546875*^9, 
  3.498173335234375*^9}, {3.498173474734375*^9, 3.498173488390625*^9}, {
  3.498173576125*^9, 3.498173585140625*^9}, {3.498173628484375*^9, 
  3.498173630765625*^9}, {3.498173664796875*^9, 3.49817367115625*^9}}]
},
AutoGeneratedPackage->Automatic,
WindowSize->{1016, 666},
WindowMargins->{{238, Automatic}, {Automatic, 133}},
FrontEndVersion->"7.0 for Microsoft Windows (32-bit) (November 10, 2008)",
StyleDefinitions->"Default.nb"
]
(* End of Notebook Content *)

(* Internal cache information *)
(*CellTagsOutline
CellTagsIndex->{}
*)
(*CellTagsIndex
CellTagsIndex->{}
*)
(*NotebookFileOutline
Notebook[{
Cell[545, 20, 6933, 195, 392, "Input",
 InitializationCell->True]
}
]
*)

(* End of internal cache information *)
